# from django_filters import rest_framework as filters
from django_filters import filters, DateFilter, DateTimeFilter
from django_filters.rest_framework.filterset import FilterSet
from api.models import Product, ProductFormula

class ProductFilter(FilterSet):
    version = filters.CharFilter(field_name='version', lookup_expr='icontains')
    creation_date = filters.DateFromToRangeFilter()
    # # 开始时间：查询 created_at >= start_time
    # start_time = DateTimeFilter(
    #     field_name='creation_date', 
    #     lookup_expr='gte',  # gte = greater than or equal
    #     label='开始时间',
    #     help_text='格式: YYYY-MM-DD HH:MM:SS'
    # )
    # # 结束时间：查询 creation_date <= end_time
    # end_time = DateTimeFilter(
    #     field_name='creation_date', 
    #     lookup_expr='lte',  # lte = less than or equal
    #     label='结束时间',
    #     help_text='格式: YYYY-MM-DD HH:MM:SS'
    # )

    class Meta:
        model = Product
        fields = ['product_id', 'version', 'status', 'creation_date']

class ProductFormulaFilter(FilterSet):

    class Meta:
        model = ProductFormula
        fields = ['material_id', 'quantity_required', 'product']